package sg.edu.nus.iss.vmcs.store;
import java.util.*;
/*
 * @author khaing zar maung
 */
public class DescValueIterator implements Iterator {
	StoreItem[] items;
	int pos;
	public DescValueIterator(StoreItem[] items){
		this.items = items;
		pos = 0;
		
		Arrays.sort(this.items,new Comparator<StoreItem>(){			
				public int compare(StoreItem a,StoreItem b){	
					Coin aCoin = (Coin)a.getContent();
					Coin bCoin = (Coin)b.getContent();
					
					int aVal = aCoin.getValue();
					int bVal = bCoin.getValue();
					
					if(aVal < bVal) return -1;
					else if(aVal == bVal) return 0;
					else return 1;
				}
			});		
	}
	public Object next(){
		StoreItem item = items[pos++];
		return item;
	}
	public boolean hasNext(){
		if(pos >= items.length || items[pos]==null)
			return false;
		else
			return true;
	}
	public void remove(){
		throw new UnsupportedOperationException();
	}
}
